package com.sentiment.servlet;

import java.io.IOException;
import java.lang.reflect.Method;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.PropertyConfigurator;

import com.sentiment.config.Config;
import com.sentiment.database.bean.DBTest;

@SuppressWarnings("serial")
public class SetConfigServlet extends HttpServlet {
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String methodName = req.getParameter("method");
		try{
			Method method = getClass().getMethod(methodName, HttpServletRequest.class,
					HttpServletResponse.class);
			method.invoke(this, req,resp);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public void initManager(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		DBTest.main(null);
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	public void init() throws ServletException {
		Config.projectRootPath = this.getServletContext().getRealPath("");

		Config.log4jPropertiesPath = Config.projectRootPath + "/WEB-INF/log4j.Properties";
		Config.xmlTitleFilter = Config.projectRootPath + "/WEB-INF/titleFilter.xml";
		Config.crawlerDataPath = Config.projectRootPath + "/crawlerData/";
		Config.htmlSavingPath = Config.projectRootPath +"/htmlSaving/";
		Config.paraXmlPath = Config.projectRootPath + "/WEB-INF/para.xml";
		Config.relativePath = this.getServletContext().getContextPath();
		PropertyConfigurator.configure(Config.log4jPropertiesPath);
		//读取标题过滤配置文件
//		TitleFilter.loadConfiguration();
		
	}
}
